package com.infocollect.project.api.ui;

import com.infocollect.project.api.entity.TappUserControlEntity;
import com.infocollect.project.api.req.UserControlPage;
import com.infocollect.project.api.service.ITappUserControlService;
import com.infocollect.project.form.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 刘亚平
 * @since 2021-06-23
 */
@Slf4j
@Api(value="TappUserControlController",tags = "用户控件接口")
@RestController
@RequestMapping("/tappusercontrol")
public class TappUserControlController {
    @Autowired
    private ITappUserControlService tappUserControlService;

    @ApiOperation("查询单个TappUserControlEntity")
    @PostMapping("/selectById")
    public R<TappUserControlEntity> selectById(@RequestParam("id") Long id) {
            return R.newOk(tappUserControlService.getById(id));
    }
    @ApiOperation("通过主键ID进行删除")
    @PostMapping("/deleteById")
    public R deleteById(@RequestParam("id") Long id) {
        if(tappUserControlService.deleteById(id)){
              return R.newOk();
             //return R.newOk();
        }else{
                return R.newError("删除失败！");
              // return R.newError("删除失败！");
        }
    }

    @ApiOperation("添加用户控件入库")
    @PostMapping("/addusercontrol")
    public R addUserControlInfo(@RequestBody TappUserControlEntity req){
        if(tappUserControlService.addUserControlInfo(req)){
            return R.newOk();
        }else{
            return R.newError("添加用户控件入库失败！");
        }
    }
    @ApiOperation("查询用户控件功能")
    @PostMapping("/queryusercontrollist")
    public R<UserControlPage> queryUserControlList(@RequestBody UserControlPage page) {
       return R.newOk(tappUserControlService.queryUserControlList(page));
    }
}